<template>
    <el-dialog :close-on-click-modal='false' title="添加项目确认" :visible.sync="dialogVisible" @close="resetForm('addForm')" width="400px">
        <el-form label-position="top" :model="addForm" :hide-required-asterisk='true' ref="addForm" :rules="addBrandRules" class="dialog_form">
            <el-form-item label="平台名称" prop="channel">
                <el-select v-model="addForm.channel" placeholder="请选择" style="width:100%" @change="selectChannel">
                    <el-option v-for="item in brandOption" :key="item.id" :label="item.nickname" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="业务场景" prop="type">
                <el-select v-model="addForm.type" placeholder="请选择" style="width:100%">
                    <el-option label="短视频" :value="5"></el-option>
                    <el-option label="直播" :value="6" v-if="addForm.channel==1 || addForm.channel==2"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('addForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('addForm')" :disabled="loading" :loading="loading" class="el-button-width">继 续</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
        return {
            dialogVisible: false,
            addForm: {
                channel: 1,
                type: 5,
            },
            addBrandRules: {
                channel: [
                    {
                        required: true,
                        message: "请选择平台名称",
                        trigger: ["blur", "change"],
                    },
                ],
                type: [
                    {
                        required: true,
                        message: "请选择业务场景",
                        trigger: ["blur", "change"],
                    },
                ],
            },
            brandOption: [
                {
                    id: 1,
                    nickname: "千川",
                },
                {
                    id: 2,
                    nickname: "UD",
                },
                {
                    id: 3,
                    nickname: "巨量",
                },
                {
                    id: 4,
                    nickname: "腾讯",
                },
                {
                    id: 5,
                    nickname: "Tiktok",
                },
                {
                    id: 6,
                    nickname: "京易投",
                },
            ],
            seccenOption: [
                {
                    id: 5,
                    nickname: "短视频",
                },
                {
                    id: 6,
                    nickname: "直播",
                },
            ],
        };
    },
    created() {},
    methods: {
        getData(data){
            this.dialogVisible = true
            this.addForm = data
        },
        selectChannel(id){
            if(id==3||id==4||id==5){
                this.addForm.type = 5
            }
        },

        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.$router.push({
                        path: "/addproject",
                        query: {
                            channel: this.addForm.channel,
                            type: this.addForm.type,
                        },
                    });
                } else {
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
    components: {},
};
</script>


<style scoped>
</style>
